package com.bw.base.net.mvvm

import androidx.lifecycle.ViewModel
import com.bw.base.net.net.ApiService
import com.bw.base.net.net.RetrofitUtlis
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

open class BaseViewModel:ViewModel() {
    var apiService:ApiService=RetrofitUtlis.getRetrofit().create(ApiService::class.java)
    //在实际调用经常使用body类型的参数，提出公共部分
    fun mapToBody(map:Map<String,Any>):RequestBody{
        val json=Gson().toJson(map)
        val body=RequestBody.create("application/json;charset=utf-8".toMediaType(),json)
        return body
    }
}